import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/service/global_service.dart';
import '../../../mixin/vehicle_type_mixin.dart';
import 'tech_form_base.dart';

class VoltageForm extends StatelessWidget with VehicleTypeMixin {
  final RxDouble voltage;
  final double height;
  const VoltageForm(this.voltage, {required this.height, super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      final vehicleType = GlobalService.to.currentVehicleType;
      final low = vehicleType.getLowVoltageThreshold();
      final high = vehicleType.getHighVoltageThreshold();
      return TechFormBase(
        value: voltage.value,
        height: height,
        unit: 'V',
        valueLabel: local.current_voltage,
        icon: Icons.battery_charging_full,
        colorBuilder: (v) {
          if (v < low) {
            return Colors.orangeAccent;
          }
          if (v > high) {
            return Colors.redAccent;
          }
          return Colors.greenAccent;
        },
        statusBuilder: (v) {
          if (v < low) {
            return TechFormStatus(local.overvoltage, Colors.orangeAccent);
          }
          if (v > high) {
            return TechFormStatus(local.undervoltage, Colors.redAccent);
          }
          return TechFormStatus(local.normal, Colors.greenAccent);
        },
        statusIconBuilder: (v) {
          if (v < low) {
            return Icons.battery_alert;
          }
          if (v > high) {
            return Icons.warning_amber_rounded;
          }
          return Icons.battery_charging_full;
        },
      );
    });
  }
}
